<?php

namespace common\models;

use common\components\redis\Connection;
use Yii;

/**
 * This is the model class for table "d_try.order_info".
 *
 * @property integer $order_info_id
 * @property string $order_sn
 * @property integer $bestry_uid
 * @property integer $order_type
 * @property string $create_time
 * @property integer $status
 * @property integer $pay_status
 * @property integer $pay_id
 * @property string $pay_name
 * @property string $bank
 * @property string $delivery_code
 * @property string $goods_amount
 * @property string $order_amount
 * @property double $member_money
 * @property double $reduce_amount
 * @property integer $coupon_id
 * @property string $coupon_code
 * @property double $coupon_amount
 * @property double $ship_amount
 * @property integer $is_invoice
 * @property string $remark
 * @property string $update_time
 * @property string $discount_amount
 * @property integer $try_coin
 * @property integer $source
 * @property integer $ship_amount_try_coin
 * @property Connection $redis
 */
class OrderInfoHistory extends \yii\db\ActiveRecord
{
    public $redis;

    public function init()
    {
        $this->redis = Yii::$app->redis;
        parent::init();
    }

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'd_order_history.order_info';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['bestry_uid', 'type', 'status', 'pay_status', 'pay_id', 'coupon_id', 'ship_amount_try_coin', 'is_invoice', 'try_coin', 'source'], 'integer'],
            [['create_time', 'update_time'], 'safe'],
            [['goods_amount', 'order_amount', 'member_money', 'reduce_amount', 'coupon_amount', 'ship_amount', 'discount_amount'], 'number'],
            [['order_sn', 'bank'], 'string', 'max' => 30],
            [['pay_name'], 'string', 'max' => 40],
            [['coupon_code'], 'string', 'max' => 60],
            [['remark'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'order_info_id' => '订单自增长id',
            'order_sn' => '订单号',
            'bestry_uid' => '会员uid',
            'type' => '订单类型',
            'create_time' => '订单添加时间',
            'status' => '订单状态',
            'pay_status' => '支付结果：1成功 0失败 2取消 3等待',
            'pay_id' => '支付方式id',
            'pay_name' => '支付方式名称',
            'bank' => '银行简码',
            'goods_amount' => '商品总金额',
            'order_amount' => '订单总金额',
            'member_money' => '余额支付金额',
            'reduce_amount' => '优惠金额',
            'coupon_id' => '优惠券id',
            'coupon_code' => '优惠券代码',
            'coupon_amount' => '优惠券金额',
            'ship_amount' => '运费',
            'ship_amount_try_coin'=>'试豆运费',
            'is_invoice' => '是否开发票 1开 0不开',
            'remark' => '用户订单的特殊需求',
            'update_time' => '订单修改时间',
            'discount_amount' => '商品折扣',
            'try_coin' => '喜元抵扣的数量',
            'source' => '0是PC订单 1是微信WAP订单',
        ];
    }

    /**
     * @inheritdoc
     * @return \services\models\OrderInfoQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new \services\models\OrderInfoQuery(get_called_class());
    }

    //关系 order_info == order_express
    public function getLgistics(){
        return $this->hasOne(OrderExpressHistory::className(), ['order_info_id' => 'order_info_id']);
    }

}
